#!/usr/bin/env python
# -*- coding: utf-8 -*-

########################################################################
"""
Name:glsl2header.py
Author:tomita
Date: 2010/04/01(Thu) PM 07:25:19
Description: glslのシェーダーコードをヘッダファイルに変換
"""
########################################################################
import re 

def convert(shaderFileName, valName='vertexShaderCode'):
    result=['static const char %s[]="\\' % valName]
    return result+['%s\\n\\' % re.sub('//.*','',x[:-1]) for x in open(shaderFileName).readlines()]+['";']

def MakeShaderHeader(namespace,
                     vertexShaderFileName,
                     fragmentShaderFileName,
                     outShaderHeaderFileName):
    
    fp=open(outShaderHeaderFileName,'w')
    fp.write('namespace %s\n{\n%s\n}\n' % (namespace,'\n'.join(convert(vertexShaderFileName,'vertexShaderCode')+convert(fragmentShaderFileName,'fragmentShaderCode'))))
    fp.close()
    
if __name__=='__main__':
    MakeShaderHeader('ShapeShaderCode','shapeshader.vsh','shapeshader.psh','./../../xed_vfx_engine/xed/shapeshadercode.h')
    MakeShaderHeader('ViewerShaderCode','viewershader.vsh','viewershader.psh','./../../xed_vfx_engine/xed/viewershadercode.h')
    

    

